home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume2 / graphics / surf_2.of < prev    next >
Text File  |  1988-10-21  |  56KB  |  2,322 lines

  1. Path: xanth!mcnc!rutgers!mailrus!ames!ll-xn!adelie!infinet!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v02i003:  surf - produce bezier surfaces of revolution, Part02/03
  5. Message-ID: <9733@swan.ulowell.edu>
  6. Date: 20 Oct 88 01:33:33 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 2311
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: edavies@uvvm.bitnet (Eric Davies)
  12. Posting-number: Volume 2, Issue 3
  13. Archive-name: graphics/surf.2of3
  14.  
  15. # This is a shell archive.  Remove anything before this line
  16. # then unpack it by saving it in a file and typing "sh file"
  17. # (Files unpacked will be owned by you and have default permissions).
  18. # This archive contains the following files:
  19. #    ./gadgetdef.h
  20. #    ./gadgetuse.c
  21. #    ./getfilenames.c
  22. #    ./graypat.c
  23. #    ./lattice.make
  24. #    ./main.c
  25. #    ./manx.makefile
  26. #    ./mapcalc.c
  27. #    ./mapimgpix.c
  28. #    ./mapstuff.c
  29. #    ./mapstuff.h
  30. #    ./menu_color.c
  31. #    ./menu_files.c
  32. #    ./menu_image.c
  33. #    ./menu_scrn.c
  34. #
  35. if `test ! -s ./gadgetdef.h`
  36. then
  37. echo "writing ./gadgetdef.h"
  38. cat > ./gadgetdef.h << '\Rogue\Monster\'
  39. #ifndef GADGETDEF_H_FILE
  40. #define GADGETDEF_H_FILE
  41. #include "mytypes.h"
  42.  
  43. #define MPtrXOffset -1L
  44. #define MPtrYOffset -1L
  45. #define MPtrCol17 623L
  46. #define MPtrCol18 0L
  47. #define MPtrCol19 976L
  48.  
  49. extern UWORD *HourGlass;
  50.  
  51. extern void InitGadgets();
  52. extern void EndGadgets();
  53. extern void GadgetHandler();
  54.  
  55. enum GadgetName { N_DefLines, N_EditLines, N_EditBez, N_Map, N_Wire,
  56.                   N_Shaded, N_TiltAng, N_PtIntens, N_BkIntens, N_SurfDist,
  57.                   N_PtLocX, N_PtLocY, N_PtLocZ, N_BezSlices, N_RevSlices,
  58.                   N_RevAngle, N_Kspec, N_Kdiffuse, N_GoPanel, N_GoSurf,
  59.                   N_BackPlane, N_RevStart, N_RepH, N_RepV };
  60.  
  61. struct GadExtens {
  62.     float minfval, maxfval, curfval; /* min,max, and cur float values */
  63.     short minival, maxival, curival; /* same but short ints */
  64.     bool isfloat;   /* true if value is floating, false if short */
  65. };
  66.  
  67. #endif GADGETDEF_H_FILE
  68. \Rogue\Monster\
  69. else
  70.   echo "will not over write ./gadgetdef.h"
  71. fi
  72. if `test ! -s ./gadgetuse.c`
  73. then
  74. echo "writing ./gadgetuse.c"
  75. cat > ./gadgetuse.c << '\Rogue\Monster\'
  76. /* this file contains definition for the screen */
  77.  
  78. #include "scrnio.ih"
  79. #include <exec/memory.h>
  80. #ifdef MANX
  81. #include <functions.h>
  82. #endif
  83.  
  84. #include "scrndef.h"
  85. #include "gadgetdef.h"
  86. #include "mytypes.h"
  87. #include "poly.h"
  88. #include "readilbm.h"
  89.  
  90. #define GetExtens(gei) ((struct GadExtens *)gei->UserData)
  91.  
  92.  
  93. void GadgetSetVal(gad)
  94.     struct Gadget *gad;
  95. {
  96.     struct GadExtens *vp;
  97.     struct PropInfo *prop;
  98.     long gadval;
  99.  
  100.     if( !(gad->GadgetType & PROPGADGET) ) {
  101.         return;
  102.     }
  103.  
  104.     if( !gad->GadgetRender ) {
  105.         gad->GadgetRender = (APTR) malloc(sizeof(struct Image));
  106.     }
  107.     if( !gad->SpecialInfo ) {
  108.         static struct PropInfo dummyprop = {
  109.             FREEHORIZ|AUTOKNOB,
  110.             0x8000, 1, /* HorizPot = initial value */
  111.             0xff, 0, /* not really of interest */
  112.             0,0,0,0,0,0
  113.         };
  114.  
  115.         gad->SpecialInfo = (APTR) malloc(sizeof(struct PropInfo));
  116.         *(struct PropInfo *)gad->SpecialInfo = dummyprop;
  117.     }
  118.  
  119.     vp = GetExtens( gad );
  120.     if(!vp)  {
  121.         return;
  122.     }
  123.     prop = (struct PropInfo *) gad->SpecialInfo;
  124.  
  125.     if( vp->isfloat ) {
  126.         gadval = (long)( (long)MAXPOT *
  127.             ( vp->curfval - vp->minfval )/(vp->maxfval - vp->minfval));
  128.         prop->HorizBody = MAXPOT /( 15 * 8 );
  129.     }
  130.     else {
  131.         gadval = ( (long)MAXPOT *
  132.             ( (long) vp->curival - vp->minival))/(vp->maxival - vp->minival);
  133.         prop->HorizBody = MAXPOT /( vp->maxival - vp->minival );
  134.     }
  135.  
  136.     prop->HorizPot = gadval;
  137. }
  138.  
  139.  
  140.  
  141. void GadgetUpdate(gad, exists)
  142.     struct Gadget *gad;
  143.     bool exists; /* has the gadget already been displayed? */
  144. {
  145.     struct GadExtens *vp;
  146.     long potvalue;
  147.     char dbuff[25];
  148.     char *tx, *dx;
  149.     struct IntuiText *it;
  150.  
  151.     if(!( gad->GadgetType & PROPGADGET) ) {
  152.         return;
  153.     }
  154.  
  155.     vp = GetExtens( gad );
  156.     if(!vp) return;
  157.  
  158.     potvalue = ((struct PropInfo *) gad->SpecialInfo)->HorizPot;
  159.  
  160.     if( vp->isfloat ) {
  161.         float temp;
  162.         temp = ( potvalue * (vp->maxfval - vp->minfval ))/ MAXPOT
  163.                 + vp->minfval;
  164.         vp->curfval = temp;
  165. #if !MANX
  166.         sprintf(dbuff,"%f   ", temp);
  167. #else
  168.         ftoa(temp, dbuff, sizeof(dbuff)-4, 1);
  169. #endif !MANX
  170.     }
  171.     else {
  172.         long temp;
  173.         temp = (long)( potvalue * (vp->maxival - vp->minival ))/ MAXPOT
  174.                 + vp->minival;
  175.         vp->curival = temp;
  176.         sprintf(dbuff,"%-12d", temp);
  177.     }
  178.     /*
  179.      * find '['
  180.      */
  181.     it = gad->GadgetText;
  182.     for( tx = (char *)it->IText; *tx && *tx != '['; tx++ ) {
  183.         ;
  184.     }
  185.     if( !*tx ) {
  186.         return; /* something screwy */
  187.     }
  188.     tx++; /* skip past opening bracket */
  189.     dx = dbuff;
  190.     while( *tx != ']' ) {
  191.         *tx++ = *dx++;
  192.     }
  193.  
  194.     if(exists){
  195.         long tempx, tempy;
  196.         tempx = it->LeftEdge + gad->LeftEdge;
  197.         tempy = it->TopEdge + gad->TopEdge + 6; /*fudge factor for baseline*/
  198.         Move( CntrlWin->RPort, tempx, tempy );
  199.         SetAPen(CntrlWin->RPort,it->FrontPen );
  200.         Text( CntrlWin->RPort, it->IText, strlen(it->IText ));
  201.     }
  202. }
  203.  
  204. SetHourGlass() {
  205.         SetPointer( SurfWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
  206.         SetPointer( GadWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
  207.         SetPointer( CntrlWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
  208.  
  209. }
  210.  
  211. ClearHourGlass() {
  212.         ClearPointer(SurfWin);
  213.         ClearPointer(GadWin);
  214.         ClearPointer(CntrlWin);
  215. }
  216.  
  217. void GadgetHandler(gadaddr)
  218.     struct Gadget *gadaddr;
  219. {
  220.     short curival;
  221.     float curfval;
  222.  
  223.     if( gadaddr->UserData ) {
  224.         GadgetUpdate( gadaddr, true );
  225.         curival = ((struct GadExtens *) gadaddr->UserData)->curival;
  226.         curfval = ((struct GadExtens *) gadaddr->UserData)->curfval;
  227.     }
  228.  
  229.     switch( (enum GadgetName) gadaddr->GadgetID ) {
  230.     case N_PtLocX:
  231.         LightSrc.x = (float)curival;
  232.         break;
  233.     case N_PtLocY:
  234.         LightSrc.y = (float)curival;
  235.         break;
  236.     case N_BackPlane:
  237.         BackColor = curival;
  238.         break;
  239.     case N_PtLocZ:
  240.         LightSrc.z = (float)curival;
  241.         break;
  242.     case N_BkIntens:
  243.         Ambience = curfval;
  244.         break;
  245.     case N_PtIntens:
  246.         PtIntensity = curfval;
  247.         break;
  248.     case N_Kdiffuse:
  249.         Kd = curfval;
  250.         break;
  251.     case N_Kspec:
  252.         Ks = curfval;
  253.         break;
  254.     case N_Map:
  255.         /* ResetCurve(); */
  256.         SetHourGlass();
  257.         RevMap();
  258.         ClearHourGlass();
  259.         break;
  260.     case N_Wire:
  261.         SetHourGlass();
  262.         RevNoShade();
  263.         ClearHourGlass();
  264.         break;
  265.     case N_Shaded:
  266.         SetHourGlass();
  267.         RevShade();
  268.         ClearHourGlass();
  269.         break;
  270.     case N_EditBez:
  271.         SetFitBez();
  272.         break;
  273.     case N_DefLines:
  274.         SetPolyDraw();
  275.         break;
  276.     case N_RevAngle:
  277.         SetRotRange( curival );
  278.         break;
  279.     case N_RevStart:
  280.         SetRotStart( curival );
  281.         break;
  282.     case N_TiltAng:
  283.         SetSecAng( curival );
  284.         break;
  285.     case N_RevSlices:
  286.         SetRevMesh( curival );
  287.         break;
  288.     case N_BezSlices:
  289.         SetBezMesh( curival );
  290.         break;
  291.     case N_SurfDist:
  292.         SetSurfDist( curival);
  293.         break;
  294.     case N_RepV:
  295.         MapRepV = curival;
  296.         PrepImgPix();
  297.         break;
  298.     case N_RepH:
  299.         MapRepH = curival;
  300.         PrepImgPix();
  301.         break;
  302.     case N_GoSurf:
  303.         ScreenToFront( SurfScrn );
  304.         break;
  305.     case N_GoPanel:
  306.         WBenchToFront();
  307.         WindowToFront( CntrlWin );
  308.         break;
  309.     default:
  310.         break;
  311.     }
  312. }
  313. \Rogue\Monster\
  314. else
  315.   echo "will not over write ./gadgetuse.c"
  316. fi
  317. if `test ! -s ./getfilenames.c`
  318. then
  319. echo "writing ./getfilenames.c"
  320. cat > ./getfilenames.c << '\Rogue\Monster\'
  321. #include <intuition/intuition.h>
  322. #include "scrnio.ih"
  323. #include <exec/memory.h>
  324. #ifdef MANX
  325. #include <functions.h>
  326. #endif
  327.  
  328. #include "scrndef.h"
  329. #include "mytypes.h"
  330.  
  331.  
  332. #define StringSize 40
  333. #define ROW 8
  334. #define COL 8
  335. #define TextX COL
  336. #define TextY (ROW/2)
  337. #define StringX 8
  338. #define StringY 12
  339. #define ReqSizeX 50*COL
  340. #define ReqSizeY 6*ROW
  341.  
  342. #define CodeGo 100
  343. #define CodeCancel 101
  344.  
  345. /*
  346.  * declarations for a cancel button to be used by both
  347.  * requestors.
  348.  */
  349. static struct IntuiText TextCancel = {
  350.     1,-1,JAM1, 2, 1, NULL,(UBYTE *) "Cancel", NULL };
  351.  
  352. static short S_Cancel[] = {
  353.     -2,-1,  -2,ROW+1,  6*COL+2,ROW+1,  6*COL+2,-1, -2,-1
  354.  };
  355.  
  356. static struct Border B_Cancel = { 0, 0, 1, 0, JAM1, 5, S_Cancel, NULL };
  357.  
  358. static struct Gadget G_Cancel = {
  359.     NULL,
  360.     10*COL, ROW *4, 6*COL, ROW, /* loc and size of hit box */
  361.     GADGHBOX,    /* complemented when pressed */
  362.     RELVERIFY,    /* just get gadget up messages */
  363.     BOOLGADGET | REQGADGET,
  364.     (APTR)&B_Cancel, NULL,
  365.     &TextCancel,
  366.     0, NULL,
  367.     (int)CodeCancel,
  368.     NULL
  369.  };
  370.  
  371. /*
  372.  * String gadget to get ilbm filename
  373.  */
  374. static char OutTitle[] = { "output filename:" };
  375. static char InTitle[] = { "input filename:" };
  376.  
  377. static struct IntuiText TextOutFile = {
  378.     1,1,JAM1, TextX, TextY, NULL,
  379.     (UBYTE *)OutTitle, NULL
  380.  };
  381. static struct IntuiText TextInFile = {
  382.     1,1,JAM1, TextX, TextY, NULL,
  383.     (UBYTE *)InTitle, NULL
  384.  };
  385.  
  386.  
  387. static char OutNameBuff[StringSize] = { "out.ilbm" };
  388. static char InNameBuff[StringSize] =  { "in.ilbm" };
  389. static char undo[StringSize];
  390.  
  391. static struct StringInfo S_OutFile = {
  392.     (UBYTE *)OutNameBuff,
  393.     (UBYTE *)undo,
  394.     0,
  395.     sizeof( OutNameBuff),
  396.     0,
  397.     0,
  398.     13,
  399.     0,
  400.     0,0,NULL,0, NULL
  401. };
  402.  
  403. static struct StringInfo S_InFile = {
  404.     (UBYTE *)InNameBuff,
  405.     (UBYTE *)undo,
  406.     0,
  407.     sizeof( InNameBuff),
  408.     0,
  409.     0,
  410.     13,
  411.     0,
  412.     0,0,NULL,0, NULL
  413. };
  414.  
  415. static short BD_InOut[] = {
  416.     -2,-1,  -2, ROW,  (StringSize-1)*COL+1,ROW,
  417.     (StringSize-1)*COL+1,-1, -2, -1
  418.  };
  419.  
  420. static struct Border B_InOut = { 0, 0, 1, 0, JAM1, 5, BD_InOut, NULL };
  421.  
  422. static struct Gadget G_OutFile = {
  423.     &G_Cancel,
  424.     StringX , StringY,   /* loc */
  425.     sizeof(OutNameBuff)*COL, ROW, /* size */
  426.     GADGHCOMP,
  427.     RELVERIFY /* | STRINGCENTER */,
  428.     STRGADGET | REQGADGET,
  429.     (APTR)&B_InOut, /* border */
  430.     NULL, /* high lighted */
  431.     &TextOutFile,
  432.     0,
  433.     (APTR) &S_OutFile,
  434.     (int)CodeGo,
  435.     NULL
  436.  };
  437.  
  438.  
  439. static struct Gadget G_InFile = {
  440.     &G_Cancel,
  441.     StringX , StringY,   /* loc */
  442.     sizeof(InNameBuff)*COL, ROW, /* size */
  443.     GADGHCOMP,
  444.     RELVERIFY/* | STRINGCENTER */,
  445.     STRGADGET | REQGADGET,
  446.     (APTR)&B_InOut, /* border */
  447.     NULL, /* high lighted */
  448.     NULL, /* text */
  449.     0,
  450.     (APTR) &S_InFile,
  451.     (int)CodeGo,
  452.     NULL
  453.  };
  454.  
  455. static struct Requester R_InFile = {
  456.     NULL,
  457.     COL*10, ROW*4, ReqSizeX, ReqSizeY,
  458.     0, 0,
  459.     &G_InFile,
  460.     NULL,
  461.     &TextInFile,
  462.     NULL,
  463.     2, /* backfill */
  464.     NULL,
  465.     { NULL },
  466.     { NULL },
  467.     NULL,
  468.     { NULL },
  469. };
  470.  
  471.  
  472.  
  473.  
  474. static struct Requester R_OutFile = {
  475.     NULL,
  476.     COL*10, ROW*4, ReqSizeX, ReqSizeY,
  477.     0, 0,
  478.     &G_OutFile,
  479.     NULL,
  480.     &TextOutFile,
  481.     NULL,
  482.     2, /* backfill */
  483.     NULL,
  484.     { NULL },
  485.     { NULL },
  486.     NULL,
  487.     { NULL },
  488. };
  489.  
  490. static bool
  491. WaitForUser() {
  492.     struct IntuiMessage mycopy,
  493.                         *orig;
  494.     long wakeupmask;
  495.  
  496.     for(;;) {
  497.         wakeupmask = Wait( 1<< CntrlWin->UserPort->mp_SigBit );
  498.  
  499.         /*
  500.          * handle messages for the control window
  501.          */
  502.  
  503.         while( orig =(struct IntuiMessage *) GetMsg( CntrlWin->UserPort ) ) {
  504.  
  505.             mycopy = *orig;
  506.             ReplyMsg( orig );
  507.  
  508.             if( mycopy.Class == GADGETUP ) {
  509.                 USHORT code;
  510.  
  511.                 code = ((struct Gadget*)mycopy.IAddress)->GadgetID;
  512.                 if( code == CodeGo ) return( true );
  513.                 if( code == CodeCancel) return(false);
  514.             }
  515.         }
  516.     }
  517. }
  518.  
  519.  
  520.  
  521. char *GetInFile()
  522. {
  523.     bool answer;
  524.     Request( &R_InFile, CntrlWin);
  525.     answer = WaitForUser();
  526.     EndRequest( &R_InFile, CntrlWin);
  527.     return( answer?InNameBuff: NULL);
  528. }
  529.  
  530.  
  531. char *GetOutFile()
  532. {
  533.     bool answer;
  534.     Request( &R_OutFile, CntrlWin);
  535.     answer = WaitForUser();
  536.     EndRequest( &R_OutFile, CntrlWin);
  537.     return( answer?OutNameBuff: NULL);
  538. }
  539.  
  540.  
  541.  
  542.  
  543. \Rogue\Monster\
  544. else
  545.   echo "will not over write ./getfilenames.c"
  546. fi
  547. if `test ! -s ./graypat.c`
  548. then
  549. echo "writing ./graypat.c"
  550. cat > ./graypat.c << '\Rogue\Monster\'
  551. #include <exec/types.h>
  552. /*
  553.  * a set of gray scales so we can pretend to have a few more colors
  554.  * (hopefully, 8 times as many)
  555.  * derived from a set of files by Karl Kashinsky
  556.  */
  557. UWORD GrayPat[9][4] = {
  558.     {
  559.         0x0000,        0x0000,        0x0000,        0x0000
  560.     },
  561.  
  562.     {
  563.         0x8080,        0x0202,        0x4040,        0x1010
  564.     },
  565.  
  566.     {
  567.         0xaaaa,        0x0000,        0x5555,        0x0000
  568.     },
  569.  
  570.     {
  571.         0xA2A2,        0x1515,        0xA8A8,        0x4545
  572.     },
  573.  
  574.     {
  575.         0xAAAA,        0x5555,        0xAAAA,        0x5555
  576.     },
  577.  
  578.     {
  579.         0x7777,        0xDDDD,        0xBBBB,        0xEEEE
  580.     },
  581.  
  582.     {
  583.         0xAAAA,        0xffff,        0x5555,        0xffff
  584.     },
  585.  
  586.     {
  587.         0x7F7F,        0xFDFD,        0xBFBF,        0xEFEF
  588.     },
  589.  
  590.     {
  591.         0xffff,        0xffff,        0xffff,        0xffff
  592.     }
  593. };
  594.  
  595. \Rogue\Monster\
  596. else
  597.   echo "will not over write ./graypat.c"
  598. fi
  599. if `test ! -s ./lattice.make`
  600. then
  601. echo "writing ./lattice.make"
  602. cat > ./lattice.make << '\Rogue\Monster\'
  603. .c.o:
  604.     copy $*.c to ram:
  605.     lc -ct -f -oram:$@ ram:$*.c
  606.     copy ram:$@ to $@
  607.     -delete ram:$@
  608.     -delete ram:$*.c
  609.  
  610. ofiles = scrnio.o scrnops.o scrndef.o main.o gadgetdef.o menudef.o graypat.o mouse.o gadgetuse.o
  611. gfiles = bezpt.o revolve.o control.o poly.o fasttrig.o
  612. imagefiles = readilbm.o writeilbm.o packer.o mapstuff.o mapcalc.o getfilenames.o mapimgpix.o
  613.  
  614. all:    surf MergeRGB
  615.  
  616.  
  617. MergeRGB:    MergeRGB.o
  618.         Blink with MergeRGB.lnk
  619.  
  620. Surf:        $(ofiles) $(gfiles) $(imagefiles)
  621.         blink with surf.lnk
  622.  
  623. bezpt.o:        scrnio.h control.h bezpt.h mytypes.h
  624.  
  625. control.o:      bezpt.h control.h scrnio.h mytypes.h
  626.  
  627. fasttrig.o:     fasttrig.h
  628.  
  629. getfilenames.o:  scrnio.ih scrndef.h mytypes.h
  630.  
  631. gadgetdef.o:    scrnio.ih scrndef.h gadgetdef.h mytypes.h bezpt.h poly.h revolve.h
  632.  
  633. gadgetuse.o:    scrnio.ih scrndef.h gadgetdef.h mytypes.h poly.h
  634.  
  635. main.o: scrnio.h mytypes.h
  636.  
  637. menu_files.o:   gadgetdef.h
  638.  
  639. menu_scrn.o:    scrndef.h
  640.  
  641. menudef.o:      scrnio.h menudef.h scrndef.h poly.h menu_color.c menu_scrn.c menu_image.c menu_files.c
  642.  
  643. mouse.o:        scrnio.ih scrnio.h mytypes.h bezpt.h control.h
  644.  
  645. poly.o: mytypes.h scrnio.h bezpt.h revolve.h control.h poly.h readilbm.h
  646.  
  647. readilbm.o mapimgpix.o:     readilbm.h
  648.  
  649. revolve.o:      fasttrig.h bezpt.h revolve.h mytypes.h
  650.  
  651. scrndef.o:      scrndef.h
  652.  
  653. mapcalc.o:      mytypes.h mapstuff.h
  654.  
  655. mapstuff.o:     poly.h mapstuff.h
  656.  
  657. \Rogue\Monster\
  658. else
  659.   echo "will not over write ./lattice.make"
  660. fi
  661. if `test ! -s ./main.c`
  662. then
  663. echo "writing ./main.c"
  664. cat > ./main.c << '\Rogue\Monster\'
  665. #include "scrnio.h"
  666. #include "mytypes.h"
  667.  
  668. main()
  669. {
  670.     InitWindow();
  671.   /*  ClrWindow(true); */
  672.     SwitchBox();
  673.     CloseDisplay();
  674. }
  675.  
  676. \Rogue\Monster\
  677. else
  678.   echo "will not over write ./main.c"
  679. fi
  680. if `test ! -s ./manx.makefile`
  681. then
  682. echo "writing ./manx.makefile"
  683. cat > ./manx.makefile << '\Rogue\Monster\'
  684. ofiles = scrnio.o scrnops.o scrndef.o main.o gadgetdef.o menudef.o graypat.o mouse.o gadgetuse.o
  685. gfiles = bezpt.o revolve.o control.o poly.o fasttrig.o
  686. imagefiles = readilbm.o writeilbm.o packer.o mapstuff.o mapcalc.o getfilenames.o mapimgpix.o
  687.  
  688. CFLAGS = +L
  689.  
  690. LFLAGS = -lm32 -lc32
  691.  
  692. surf:   $(ofiles) $(gfiles) $(imagefiles)
  693.     ln -o surf $(ofiles) $(gfiles) $(imagefiles) $(LFLAGS)
  694.  
  695. bezpt.o:        scrnio.h control.h bezpt.h mytypes.h
  696.  
  697. control.o:      bezpt.h control.h scrnio.h mytypes.h
  698.  
  699. fasttrig.o:     fasttrig.h
  700.  
  701. getfilenames.o:  scrnio.ih scrndef.h mytypes.h
  702.  
  703. gadgetdef.o:    scrnio.ih scrndef.h gadgetdef.h mytypes.h bezpt.h poly.h revolve.h
  704.  
  705. gadgetuse.o:    scrnio.ih scrndef.h gadgetdef.h mytypes.h poly.h
  706.  
  707. main.o: scrnio.h mytypes.h
  708.  
  709. menu_files.o:   gadgetdef.h
  710.  
  711. menu_scrn.o:    scrndef.h
  712.  
  713. menudef.o:      scrnio.h menudef.h scrndef.h poly.h menu_color.c menu_scrn.c menu_image.c menu_files.c
  714.  
  715. mouse.o:        scrnio.ih scrnio.h mytypes.h bezpt.h control.h
  716.  
  717. poly.o: mytypes.h scrnio.h bezpt.h revolve.h control.h poly.h readilbm.h
  718.  
  719. readilbm.o mapimgpix.o:     readilbm.h
  720.  
  721. revolve.o:      fasttrig.h bezpt.h revolve.h mytypes.h
  722.  
  723. scrndef.o:      scrndef.h
  724.  
  725. mapcalc.o:      mytypes.h mapstuff.h
  726.  
  727. mapstuff.o:     poly.h mapstuff.h
  728.  
  729. \Rogue\Monster\
  730. else
  731.   echo "will not over write ./manx.makefile"
  732. fi
  733. if `test ! -s ./mapcalc.c`
  734. then
  735. echo "writing ./mapcalc.c"
  736. cat > ./mapcalc.c << '\Rogue\Monster\'
  737. #include <math.h>
  738. #include "mytypes.h"
  739. #include "revolve.h"       /* need to get scrnpair from here */
  740. #include "mapstuff.h"
  741. #include "menuexp.h"
  742.  
  743. #ifdef TEST
  744. #undef DebugOn
  745. #define DebugOn 1
  746. #endif TEST
  747.  
  748.  
  749. #define DEBUG
  750. /*
  751.  * this section of code derived from:
  752.  * "The essential algorithms of ray tracing" by Eric Haines
  753.  * presented in Sigraph proceedings on Ray Tracing
  754.  * my major change has been to simplify it for two dimensions
  755.  */
  756.  
  757. typedef struct {
  758.     float x, y;
  759. } Vector;
  760.  
  761. static float DotVector(a,b)
  762.     Vector *a, *b;
  763. {
  764.     return( a->x * b->x + a->y * b->y);
  765. }
  766.  
  767. static void DivVector(in, scale, out)
  768.     Vector *in, *out;
  769.     float scale;
  770. {
  771.     if ( fabs(scale) < SingleTinyVal ) {
  772.         out->x = SingleLargeVal;
  773.         out->y = SingleLargeVal;
  774.     }
  775.     else {
  776.         out->x = in->x / scale;
  777.         out->y = in->y / scale;
  778.     }
  779. }
  780.  
  781.  
  782.  
  783. static Vector Na, Nb, Nc;
  784. static float Du0, Du1, Du2,
  785.              Dv0, Dv1, Dv2;
  786. static Vector Qux, Quy,
  787.               Qvx, Qvy;
  788. static float Dux, Duy,
  789.              Dvx, Dvy;
  790. static bool IsQuadu, IsQuadv;
  791.  
  792. void CalcMapConsts(vp)
  793.     register ScrnPair *vp;
  794. #define p00 vp[0]
  795. #define p01 vp[1]
  796. #define p11 vp[2]
  797. #define p10 vp[3]
  798. {
  799.     Vector Pa, Pb, Pc, Pd;
  800.  
  801.     Pa.x = p00.x - p10.x + p11.x - p01.x;
  802.     Pa.y = p00.y - p10.y + p11.y - p01.y;
  803.  
  804.     Pb.x = p10.x - p00.x;
  805.     Pb.y = p10.y - p00.y;
  806.  
  807.     Pc.x = p01.x - p00.x;
  808.     Pc.y = p01.y - p00.y;
  809.  
  810.     Pd.x = p00.x;
  811.     Pd.y = p00.y;
  812.  
  813.     Na.x = Pa.y; Na.y = -Pa.x;
  814.     Nc.x = Pc.y; Nc.y = -Pc.x;
  815.     Nb.x = Pb.y; Nb.y = -Pb.x;
  816.  
  817.     Du0 = DotVector(&Nc, &Pd);
  818.     Du1 = DotVector(&Na, &Pd) + DotVector(&Nc, &Pb);
  819.     Du2 = DotVector( &Na, &Pb);
  820.  
  821.     if( fabs( Du2 ) > SingleTinyVal ) {
  822.         float TwoDu2;
  823.  
  824.         IsQuadu = true;
  825.         TwoDu2 = 2.0 * Du2;
  826.         DivVector( &Na, TwoDu2, &Qux );
  827.         DivVector( &Nc, -Du2, &Quy );
  828.         Duy = Du0/Du2;
  829.         Dux = -Du1/TwoDu2;
  830.     }
  831.     else {
  832.         IsQuadu = false;
  833.     }
  834.  
  835.     Dv0 = DotVector( &Nb, &Pd);
  836.     Dv1 = DotVector(&Na, &Pd) + DotVector(&Nb, &Pc);
  837.     Dv2 = DotVector( &Na, &Pc);
  838.     if( fabs( Dv2 ) > SingleTinyVal ) {
  839.         float TwoDv2;
  840.  
  841.         IsQuadv = true;
  842.         TwoDv2 = 2.0 * Dv2;
  843.         DivVector( &Na, TwoDv2, &Qvx);
  844.         DivVector( &Nb, -Dv2, &Qvy);
  845. /*      DivVector( &Nc, -Dv2, &Qvy); */
  846.         Dvx = - Dv1/TwoDv2;
  847.         Dvy = Dv0/Dv2;
  848.     }
  849.     else {
  850.         IsQuadv = false;
  851.     }
  852. #ifdef DEBUG
  853.     if( DebugOn ) {
  854.         printf("du2 %f, du1 %f, du0 %f\n", Du2, Du1, Du0 );
  855.         printf("dv2 %f, dv1 %f, dv0 %f\n", Dv2, Dv1, Dv0 );
  856.         printf("Na = (%f, %f), Nb = (%f,%f), Nc = (%f,%f)\n",
  857.         Na.x, Na.y, Nb.x, Nb.y, Nc.x, Nc.y );
  858.         printf("IsQuad =(%c, %c)\n", IsQuadu?'t':'f', IsQuadv? 't': 'f' );
  859.     }
  860. #endif DEBUG
  861.  
  862. }
  863.  
  864.  
  865. /*
  866.  * given points px,py in the quadrilateral, map them to points inside a
  867.  * unit square
  868.  */
  869. void  MapXYRatio(px, py, outx, outy, SweepCode)
  870.     float px, py;
  871.     float *outx, *outy;
  872.     short SweepCode;
  873. {
  874.     float resu, resv;
  875.     Vector Ri;
  876.  
  877.  
  878.     Ri.x = px; Ri.y = py;
  879.  
  880.     if( !IsQuadu ) {
  881.         float denom;
  882.         denom = (Du1 - DotVector(&Na, &Ri));
  883.         if( fabs(denom) < SingleTinyVal )
  884.             resu = 2.0;
  885.         else
  886.             resu = (DotVector(&Nc, &Ri) - Du0)/denom;
  887.     } else {
  888.         float Ka, Kb;
  889.         float discrim;
  890.  
  891.         Ka = Dux + DotVector( &Qux, &Ri);
  892.         Kb = Duy + DotVector( &Quy, &Ri);
  893.         discrim = sqrt(fabs(Ka * Ka - Kb));
  894.         resu = Ka + ((discrim > Ka)? discrim: (-discrim));
  895. #ifdef DEBUG
  896.         if( DebugOn ) {
  897.             printf("dux=%f, duy = %f, ka = %f, kb = %f\n",
  898.                 Dux, Duy, Ka, Kb );
  899.         }
  900. #endif DEBUG
  901.  
  902.     }
  903.  
  904.     if( !IsQuadv ) {
  905.         float denom;
  906.         denom = (Dv1 - DotVector(&Na, &Ri));
  907.         if( fabs(denom) < SingleTinyVal )
  908.             resv = 2.0;
  909.         else
  910.             resv = (DotVector(&Nb, &Ri) - Dv0)/denom;
  911.     } else {
  912.         float Ka, Kb;
  913.         float discrim;
  914.  
  915.         Ka = Dvx + DotVector( &Qvx, &Ri);
  916.         Kb = Dvy + DotVector( &Qvy, &Ri);
  917.         discrim = sqrt(fabs( Ka * Ka - Kb));
  918.         resv = Ka + ((discrim > Ka)? discrim: (-discrim));
  919. #ifdef DEBUG
  920.         if( DebugOn ) {
  921.             printf("dvx=%f, dvy = %f, ka = %f, kb = %f\n",
  922.                 Dvx, Dvy, Ka, Kb );
  923.         }
  924. #endif DEBUG
  925.     }
  926.  
  927. #ifdef DEBUG
  928.     if( DebugOn ) {
  929.         printf("(%f,%f) -> (%f, %f)\n", px, py, resu, resv );
  930.     }
  931. #endif DEBUG
  932.  
  933.     if( resu > 1.0 || resu < 0.0 ) {
  934.         resu = ( SweepCode & MP_XMAX)? 1.0: 0.0;
  935.     }
  936.     if( resv > 1.0 || resv < 0.0 ) {
  937.         resv = ( SweepCode & MP_YMAX)? 1.0: 0.0;
  938.     }
  939.  
  940.     *outx = resu; *outy = resv;
  941. }
  942.  
  943.  
  944.  
  945. /*
  946.  * here abides testcode
  947.  */
  948. #ifdef TEST
  949. #include <stdio.h>
  950.  
  951. ReadScrnPair(set, a)
  952.     char *set;
  953.     ScrnPair *a;
  954. {
  955.     int tx, ty;
  956.     printf("enter screen pair %s\n",set);
  957.     scanf("%d %d", &tx, &ty);
  958.     a->x = tx; a->y = ty;
  959. }
  960.  
  961. ReadLimits(a)
  962. ScrnPair a[];
  963. {
  964.     ReadScrnPair("a", &a[0]);
  965.     ReadScrnPair("b", &a[1]);
  966.     ReadScrnPair("c", &a[2]);
  967.     ReadScrnPair("d", &a[3]);
  968. }
  969.  
  970. main() {
  971.     float inx, iny;
  972.     float outy, outx;
  973.     ScrnPair pts[4];
  974.  
  975.     ReadLimits(pts);
  976.     CalcMapConsts(pts);
  977.     while(!feof(stdin)) {
  978.         printf("enter quadrilateral points\n");
  979.         scanf("%f %f", &inx, &iny );
  980.         MapXYRatio( inx, iny, &outx, &outy, 0);
  981.         printf("p(%f,%f)->p(%f,%f)\n", inx, iny, outx, outy);
  982.     }
  983. }
  984. #endif TEST
  985. \Rogue\Monster\
  986. else
  987.   echo "will not over write ./mapcalc.c"
  988. fi
  989. if `test ! -s ./mapimgpix.c`
  990. then
  991. echo "writing ./mapimgpix.c"
  992. cat > ./mapimgpix.c << '\Rogue\Monster\'
  993. #include "mytypes.h"
  994. #include "readilbm.h"
  995.  
  996. #define DefRes 2
  997. int MapImageV = DefRes*DefRepV,
  998.     MapImageH= DefRes*DefRepH; /* virtual screen size */
  999. static int PixV=DefRes,
  1000.            PixH=DefRes;  /* true ilbm size in pixels */
  1001. short MapRepV = DefRepV,
  1002.       MapRepH = DefRepH;
  1003. static short BytesPerLine;
  1004. static unsigned char *Raster= null;
  1005. static long MaxShade;
  1006. static bool AxisFlipped = DefXYFlip;
  1007. /*
  1008.  * Update the MapImageH and MapImageV variables
  1009.  */
  1010. void PrepImgPix()
  1011. {
  1012.     MapImageV = PixV * MapRepV;
  1013.     MapImageH = PixH * MapRepH;
  1014.     if( AxisFlipped ) {
  1015.         int temp;
  1016.         temp = MapImageV;
  1017.         MapImageV = MapImageH;
  1018.         MapImageH = temp;
  1019.     }
  1020. }
  1021. /*
  1022.  * free up any memory holding mapping image
  1023.  */
  1024. void CloseImgPix()
  1025. {
  1026.         if( Raster) free(Raster);
  1027.         Raster = null;
  1028.         PixV = 0xff; PixH = 0xff;
  1029.         PrepImgPix();
  1030. }
  1031.  
  1032. /*
  1033.  * cause x and y axises to be reversed
  1034.  */
  1035. void FlipImgPix( flip )
  1036.     bool flip;
  1037. {
  1038.     AxisFlipped = flip;
  1039.     PrepImgPix();
  1040. }
  1041.  
  1042. /*
  1043.  * 4 bits per pixel means 2 pixels per byte
  1044.  */
  1045. bool OpenImgPix(sizex, sizey, maxshade)
  1046.     int sizex, sizey;
  1047.     short maxshade;
  1048. {
  1049.     CloseImgPix();
  1050.     if( maxshade == 0 ) {
  1051.         OutErr("OpenImgPix: got max shade = 0\n");
  1052.         maxshade = 1;
  1053.      }
  1054.     MaxShade = maxshade;
  1055.     BytesPerLine = (sizex +1)/2;
  1056.     Raster = (unsigned char *) malloc( BytesPerLine * sizey);
  1057.     if( !Raster ) {
  1058.         printf("OpenImgPix: not enough memory\n");
  1059.         return(false); /* no memory err */
  1060.     }
  1061.  
  1062.     PixV = sizey;
  1063.     PixH = sizex;
  1064.     PrepImgPix();
  1065.     return(true);
  1066. }
  1067.  
  1068. #define CalcByte(cbx,cby) (Raster + ( BytesPerLine * cby ) + (cbx >> 1))
  1069.  
  1070.  
  1071. void SetImgPix(x, y, val)
  1072.     int x, y; /* location */
  1073.     int val;
  1074. {
  1075.     unsigned char *bite;
  1076.     unsigned char shade;
  1077.  
  1078.     if( x > PixH || x < 0 || y > PixV || y < 0 ) {
  1079.         OutErr("SetImgPix(%d,%d,%d) out of range\n",x,y,val);
  1080.         return;
  1081.     }
  1082.  
  1083.     if( !Raster) return;
  1084.     shade = ( (val<< 4)-val)/MaxShade;
  1085.     bite = CalcByte(x,y);
  1086.     if( x & 1) {
  1087.         *bite = (*bite & 0xf) | ( shade <<4 );
  1088.     }
  1089.     else {
  1090.         *bite = (*bite & 0xf0) | shade;
  1091.     }
  1092. }
  1093.  
  1094.  
  1095. short GetImgPix(x,y)
  1096.     int x, y;
  1097. {
  1098.     unsigned char *bite;
  1099.     short shade;
  1100.  
  1101.     if( AxisFlipped ) {
  1102.         int temp;
  1103.         temp = x; x = y; y = temp;
  1104.     }
  1105.  
  1106.     x %= PixH;
  1107.     y %= PixV;
  1108.  
  1109.     if( !Raster ) {
  1110.         return( ((x ^ y)& 0x10) ? 0xff: 0);
  1111.     }
  1112.     bite = CalcByte(x,y);
  1113.  
  1114.     if( x & 1) {
  1115.         return( *bite & 0xf0);
  1116.     }
  1117.     else {
  1118.         return( (*bite & 0x0f) <<4);
  1119.     }
  1120. }
  1121. \Rogue\Monster\
  1122. else
  1123.   echo "will not over write ./mapimgpix.c"
  1124. fi
  1125. if `test ! -s ./mapstuff.c`
  1126. then
  1127. echo "writing ./mapstuff.c"
  1128. cat > ./mapstuff.c << '\Rogue\Monster\'
  1129. #include <math.h>
  1130. #include "mytypes.h"
  1131. #include "poly.h"
  1132. #include "bezpt.h"
  1133. #include "revolve.h"
  1134. #include "readilbm.h"
  1135. #include "mapstuff.h"
  1136. #include "menuexp.h"
  1137.  
  1138. #define FarRight   1e6
  1139. #define FarLeft   -1e6
  1140. #define FarTop     0x7fff
  1141. #define FarBottom -0x7fff
  1142.  
  1143. /*
  1144. #ifndef MANX
  1145. #include "libraries/mathffp.h"
  1146. #define ceil    SPCeil
  1147. #define floor    SPFloor
  1148. #define fabs    SPAbs
  1149. #endif
  1150. */
  1151.  
  1152. typedef struct { float left, right; } Hedge;
  1153.  
  1154. static float *BezMapping = null,
  1155.              *RevMapping = null;
  1156. static float revmin, revdiff,
  1157.              bezmin, bezdiff;
  1158.  
  1159.  
  1160. /*
  1161.  * given the ptlist of a polygon, find its vertical range
  1162.  */
  1163. static void FindVRange(scrnlist, top, bottom)
  1164.     register ScrnPair *scrnlist;
  1165.     short *top, *bottom;
  1166. {
  1167.     short i;
  1168.     short localtop, localbot;
  1169.  
  1170.     localtop = FarBottom;
  1171.     localbot = FarTop;
  1172.  
  1173.     for( i = 4; i--; scrnlist++ ) {
  1174.         if( localtop < scrnlist->y ) localtop = scrnlist->y;
  1175.         if( localbot > scrnlist->y ) localbot = scrnlist->y;
  1176.     }
  1177.     *top = localtop;
  1178.     *bottom = localbot;
  1179. }
  1180. /*
  1181.  * allocate table to store a quick and dirty representation of the
  1182.  * quadrilateral segments
  1183.  */
  1184. static Hedge *InitVRange( depth, tabptr, olddepth )
  1185.     short depth, *olddepth;
  1186.     Hedge *tabptr;
  1187. {
  1188.     Hedge *edgel, *tab;
  1189.     if( *olddepth < depth || !tabptr ) {
  1190.         if( tabptr ) free( tabptr);
  1191.         tab = (Hedge *) malloc(sizeof(Hedge)*depth);
  1192.         *olddepth = depth;
  1193.     }
  1194.     else {
  1195.         tab = tabptr;
  1196.     }
  1197.     if( !tab ) return( null);
  1198.  
  1199.     for( edgel = tab; depth--; edgel++) {
  1200.         edgel->left = FarRight;
  1201.         edgel->right = FarLeft;
  1202.     }
  1203.     return( tab );
  1204. }
  1205.  
  1206.  
  1207. /*
  1208.  * add line to quadrilateral descriptions
  1209.  */
  1210. static void AddVLine( tab, x1, y1, x2, y2 )
  1211.     Hedge *tab;
  1212.     short x1, y1, x2, y2;
  1213. {
  1214.     short dy;
  1215.     float curx, slope;
  1216.     /*
  1217.      * want y1 to have smaller value, ie, y1 below y2
  1218.      */
  1219.     if( y1 > y2 ) {
  1220.         short temp;
  1221.         temp = y1; y1 = y2; y2 = temp;
  1222.         temp = x1; x1 = x2; x2 = temp;
  1223.     }
  1224.     dy = y2 - y1;
  1225.     tab += y1;
  1226.  
  1227.     if( !dy ) {
  1228.         if ( x1 < x2 ) {
  1229.             short tempx;
  1230.             tempx = x1; x1 = x2; x2 = tempx;
  1231.         }
  1232.         if( x2 < tab->left ) tab->left = x2;
  1233.         if( x1 > tab->right ) tab->right = x1;
  1234.         return;
  1235.     }
  1236.     slope = (float)(x2 - x1)/dy;
  1237.  
  1238.     curx = x1;
  1239. #define ZipIt(xxx) { if( xxx < tab->left) tab->left = xxx; \
  1240.                      if( xxx > tab->right ) tab->right = xxx; }
  1241.     ZipIt(curx);
  1242.     while( dy--) {
  1243.         curx += slope;
  1244.         tab++;
  1245.         ZipIt(curx);
  1246.     }
  1247. }
  1248.  
  1249.  
  1250. static void AdjMapXY( inx, iny, outpair)
  1251.     float inx, iny;
  1252.     ScrnPair *outpair;
  1253. {
  1254.     float outx, outy;
  1255.     MapXYRatio( inx, iny, &outx, &outy);
  1256.  
  1257.     outpair->y = MapImageH * (bezmin + bezdiff * outy);
  1258.     outpair->x = MapImageV * (revmin + revdiff * outx);
  1259.  
  1260. /*
  1261.     if( RevAxis == RevX ) {
  1262.         outpair->y = MapImageH * (bezmin + bezdiff * outy);
  1263.         outpair->x = MapImageV * (revmin + revdiff * outx);
  1264.     } else {
  1265.         outpair->x = MapImageH * (bezmin + bezdiff * outy);
  1266.         outpair->y = MapImageV * (revmin + revdiff * outx);
  1267.     }
  1268.  */
  1269. }
  1270.  
  1271. static void ScanCnvQuad( tab, pt)
  1272.     Hedge *tab;
  1273.     ScrnPair pt[];
  1274. {
  1275.     register int i;
  1276.     ScrnPair *listb, *liste;
  1277.  
  1278.     liste = pt;
  1279.     listb = liste + 3;
  1280.     for ( i = 4; i--;) {
  1281.         AddVLine( tab, listb->x, listb->y, liste->x, liste->y);
  1282.         listb = liste++;
  1283.     }
  1284. }
  1285.  
  1286. static float AverageShade(pts)
  1287.     ScrnPair pts[];
  1288. {
  1289.     register Hedge *tab;
  1290.     static Hedge *tabfree = null;
  1291.     static short olddepth = 0;
  1292.     short top, bot;
  1293.     long shade = 0,
  1294.          pixcnt = 0;
  1295.  
  1296.     FindVRange( pts, &top, &bot);
  1297.     tabfree = tab = InitVRange( top - bot + 1, tabfree, &olddepth);
  1298.     if(!tabfree) return(0.0);
  1299.  
  1300.     ScanCnvQuad( tab-bot, pts );
  1301. #if DEBUG
  1302.     if( DebugOn ) {
  1303.         printf("AverageShade top is %d, bot = %d\n", top, bot );
  1304.     }
  1305. #endif DEBUG
  1306.  
  1307.     while( bot <= top ) {
  1308.         register int hori;
  1309.         int right, left;
  1310. #if DEBUG
  1311.     if( DebugOn ) {
  1312.         printf("....row %d    \t%d -> %d\n", bot, left, right );
  1313.     }
  1314. #endif DEBUG
  1315.  
  1316.         left =  (int) ceil(tab->left - SingleTinyVal);
  1317.         right = (int)floor(tab->right+ SingleTinyVal);
  1318.  
  1319.         for( hori= left; hori <= right; hori++ ) {
  1320.             shade += GetImgPix( bot, hori);
  1321.             pixcnt++;
  1322.         }
  1323.  
  1324.     /*
  1325.         if( RevAxis == RevX ) {
  1326.             for( hori= left; hori <= right; hori++ ) {
  1327.                 shade += GetImgPix( bot, hori);
  1328.                 pixcnt++;
  1329.             }
  1330.         }
  1331.         else {
  1332.             for( hori= left; hori <= right; hori++ ) {
  1333.                 shade += GetImgPix( hori, bot);
  1334.                 pixcnt++;
  1335.             }
  1336.         }
  1337.     */
  1338.         tab++;
  1339.         bot++;
  1340.     }
  1341.     return( (float)shade / (pixcnt *(15 *16)) );
  1342. }
  1343.  
  1344. /*
  1345.  * mess with the number so truncation doesn't
  1346.  * do nasty things to a float containing an int
  1347.  */
  1348. static int NearestInt( afloat )
  1349.     float afloat;
  1350. {
  1351.     afloat += ( afloat > 0 )? 1e-2 : -1e-2;
  1352.     return( (int)afloat );
  1353. }
  1354.  
  1355.  
  1356. static void ShadeQuad(tab, top, bot, intensity)
  1357.     register Hedge *tab;
  1358.     short top, bot;
  1359.     float intensity;
  1360. {
  1361.     short vert;
  1362.     float rowminl, rowminr,
  1363.           rowmaxl, rowmaxr;
  1364.     Hedge *oldtab, *nexttab;
  1365.  
  1366.     for ( vert =  bot;
  1367.         nexttab = tab+1, vert <= top;
  1368.         vert++, oldtab = tab, tab++ ) {
  1369.         float hori;
  1370.         float colmin, colmax;
  1371.         float leftmost, rightmost;
  1372.         int ihori, ileftmost, irightmost;
  1373.         ScrnPair MpPnts[4];
  1374.  
  1375. #define lefttop MpPnts[0]
  1376. #define leftbot MpPnts[3]
  1377. #define righttop MpPnts[1]
  1378. #define rightbot MpPnts[2]
  1379.  
  1380.  
  1381.         rowminl = (float)vert;
  1382.         rowmaxr = rowmaxl = rowminr = rowminl;
  1383.  
  1384.         if( vert > bot && oldtab->left < tab->left ) {
  1385.             rowminl -= 0.5;
  1386.         }
  1387.         if( vert > bot && oldtab->right > tab->right ) {
  1388.             rowminr -= 0.5;
  1389.         }
  1390.         if( vert < top && nexttab->left < tab->left ) {
  1391.             rowmaxl += 0.5;
  1392.         }
  1393.         if( vert < top && nexttab->right > tab->right ) {
  1394.             rowmaxr += 0.5;
  1395.         }
  1396.  
  1397.         irightmost = NearestInt( tab->right );
  1398.         rightmost = irightmost;
  1399.         ileftmost = NearestInt( tab->left );
  1400.         leftmost = ileftmost;
  1401.         if( irightmost < ileftmost ) {
  1402.             irightmost = ileftmost;
  1403.         }
  1404.         for( ihori = leftmost, hori = leftmost;
  1405.             ihori <= irightmost;
  1406.             ihori += 1, hori += 1.0 ) {
  1407.  
  1408.  
  1409.             if( AbortDraw ) { return; }
  1410.  
  1411.             colmin = hori - 0.5;
  1412.             colmax = hori + 0.5;
  1413.  
  1414.             colmin =(colmin > leftmost)?colmin: tab->left;
  1415.             colmax =(colmax < rightmost)?colmax: tab->right;
  1416.  
  1417.             AdjMapXY( colmin, rowmaxl, &lefttop,  MP_XMIN| MP_YMAX);
  1418.             AdjMapXY( colmax, rowmaxr, &righttop, MP_XMAX| MP_YMAX);
  1419.             AdjMapXY( colmin, rowminl, &leftbot,  MP_XMIN| MP_YMIN);
  1420.             AdjMapXY( colmax, rowminr, &rightbot, MP_XMAX| MP_YMIN);
  1421.  
  1422.             PaintPoint(ihori, vert, AverageShade(MpPnts) *intensity);
  1423.         }
  1424.     }
  1425. #undef lefttop
  1426. #undef righttop
  1427. #undef rightbot
  1428. #undef leftbot
  1429. }
  1430.  
  1431.  
  1432. void DrawRhomMap(mpr)
  1433.     MapRhomboid *mpr;
  1434. {
  1435.     short top, bottom;
  1436.     short vrange, hrange;
  1437.     static Hedge *tab = null;
  1438.     static short olddepth = 0;
  1439.  
  1440.     CalcMapConsts( mpr->rhom.pt );
  1441.     FindVRange( mpr->rhom.pt, &top, &bottom );
  1442.     tab = InitVRange( top - bottom + 1, tab, &olddepth );
  1443.     if(!tab) return;
  1444.     ScanCnvQuad( tab -bottom, mpr->rhom.pt );
  1445.  
  1446.     bezmin = BezMapping[mpr->bezindex];/* make it global */
  1447.     bezdiff = BezMapping[mpr->bezindex+1] - bezmin;
  1448.     revmin = RevMapping[mpr->revindex];
  1449.     revdiff = RevMapping[mpr->revindex+1] - revmin;
  1450. #if DEBUG
  1451.     if( DebugOn ) {
  1452.         DBMAP(mpr->rhom.pt, mpr->bezindex, mpr->revindex);
  1453.     }
  1454. #endif DEBUG
  1455.     ShadeQuad(tab, top, bottom, mpr->rhom.intensity);
  1456. }
  1457.  
  1458. #ifdef DEBUG
  1459. DBMAP(ptlist, bindex, rindex)
  1460. ScrnPair ptlist[];
  1461. short bindex, rindex;
  1462. {
  1463.     int i;
  1464.  
  1465.     printf("...................................\n");
  1466.     for( i = 0; i < 4; i++ ) {
  1467.         printf("%10d", ptlist[i].x);
  1468.     };
  1469.     printf("\n");
  1470.     for( i = 0; i < 4; i++ ) {
  1471.         printf("%10d", ptlist[i].y);
  1472.     };
  1473.     printf("\n");
  1474.     printf(" bezmin %f  bezdiff %f index = %d \n", bezmin, bezdiff, bindex );
  1475.     printf(" revmin %f  revdiff %f index = %d \n", revmin, revdiff, rindex );
  1476. }
  1477. #endif DEBUG
  1478.  
  1479.  
  1480. /*
  1481.  * return true if image mappings could not be performed
  1482.  * false if successful
  1483.  */
  1484. bool InitMapping() {
  1485.     float *vfmptr;
  1486.     float totallen = 0,
  1487.           scaling;
  1488.     short numvslices;
  1489.  
  1490.     if( BezMapping ) free( BezMapping );
  1491.     if( RevMapping ) free( RevMapping );
  1492.  
  1493.     /*
  1494.      * compute width of each bezier segment
  1495.      */
  1496.     numvslices = BezMesh*GetNumSegs() +1;
  1497.     vfmptr = BezMapping = (float *) malloc(sizeof(float) * numvslices);
  1498.     if( !BezMapping ) return(true);
  1499.  
  1500.     *vfmptr++ = totallen = 0.0;
  1501.     ResetActSeg();
  1502.     do {
  1503.         float t, ffromx, ftox, ffromy, ftoy;
  1504.         int i;
  1505.         InitCalcBez();
  1506.         for( i = 1, ffromx = StartPtX(ActSeg), ffromy = StartPtY(ActSeg);
  1507.             i <= BezMesh; i++, ffromx = ftox, ffromy = ftoy ) {
  1508.             float diffx, diffy;
  1509.  
  1510.             t = (float)i/BezMesh;
  1511.  
  1512.             CalcBezPt( t, &ftox, &ftoy );
  1513.             diffx = ftox - ffromx;
  1514.             diffy = ftoy - ffromy;
  1515.             totallen += sqrt( diffx * diffx + diffy * diffy );
  1516.             *vfmptr++ = totallen;
  1517.         }
  1518.         NextSeg();
  1519.     } while( ActSeg);
  1520.     /*
  1521.      * convert scale floating point values to integer pixel positions
  1522.      */
  1523.     scaling = 1.0 / totallen;
  1524.     for( vfmptr = BezMapping; numvslices; numvslices--, vfmptr++ ) {
  1525.         *vfmptr *= scaling;
  1526.     }
  1527.     /*
  1528.      * compute height of each revolution segment
  1529.      */
  1530.     RevMapping = (float *) malloc( sizeof(float) * (RevMesh + 1));
  1531.     if( !RevMapping ) return( true );
  1532.     {
  1533.         short i;
  1534.         for( i = 0; i <= RevMesh; i++ ) {
  1535.             RevMapping[i] =  ((float) i)/RevMesh;
  1536.         }
  1537.     }
  1538.  
  1539.     return(false);
  1540. }
  1541. \Rogue\Monster\
  1542. else
  1543.   echo "will not over write ./mapstuff.c"
  1544. fi
  1545. if `test ! -s ./mapstuff.h`
  1546. then
  1547. echo "writing ./mapstuff.h"
  1548. cat > ./mapstuff.h << '\Rogue\Monster\'
  1549. #define SingleTinyVal 1.0e-12
  1550. #define SingleLargeVal 1.0e12
  1551.  
  1552. #define MP_XMIN 0
  1553. #define MP_XMAX 1
  1554. #define MP_YMIN 0
  1555. #define MP_YMAX 2
  1556.  
  1557. bool InitMapping( /* void */);
  1558.  
  1559. void CalcMapConsts();
  1560. void MapXYRatio( /* float px, py; float *outx, outy; */);
  1561. void DrawRhomMap( /* MapRhomboid  *mpr; */ );
  1562.  
  1563. \Rogue\Monster\
  1564. else
  1565.   echo "will not over write ./mapstuff.h"
  1566. fi
  1567. if `test ! -s ./menu_color.c`
  1568. then
  1569. echo "writing ./menu_color.c"
  1570. cat > ./menu_color.c << '\Rogue\Monster\'
  1571. /*
  1572.  * Menu description for selecting color mapping
  1573.  */
  1574. static struct IntuiText colortext[] = {
  1575.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"grey",  NULL },
  1576.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"red",   NULL },
  1577.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"green", NULL },
  1578.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"blue",  NULL },
  1579.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"rainbow",NULL }
  1580. };
  1581.  
  1582. #define ColNum (sizeof(colortext)/sizeof(struct IntuiText))
  1583. #define ColXMask ((1<<ColNum)-1)
  1584. #define ColorExclude(entry) (ColXMask^( 1<<entry))
  1585.  
  1586. #define COLMEMFLAGS  ( CHECKIT | ITEMTEXT | HIGHCOMP | ITEMENABLED )
  1587.  
  1588. struct MenuItem coloritems[] = {
  1589.   { &coloritems[1], /* next item */
  1590.     10, 0, 80 , 10, /* x,y,w,h */
  1591.     COLMEMFLAGS| CHECKED,
  1592.     ColorExclude(0), /* mutual exclude bits */
  1593.     (APTR) &colortext[0],  /* grey */
  1594.     NULL, /* highlight image */
  1595.     'h', /* command byte ? */
  1596.     NULL, /* submenu item */
  1597.     0 /* next select for select dragging */
  1598.     },
  1599.   { &coloritems[2], /* next item */
  1600.     10, 10, 80 , 10, /* x,y,w,h */
  1601.     COLMEMFLAGS,
  1602.     ColorExclude(1), /* mutual exclude bits */
  1603.     (APTR) &colortext[1],     /* red */
  1604.     NULL, /* highlight image */
  1605.     'h', /* command byte ? */
  1606.     NULL, /* submenu item */
  1607.     0 /* next select for select dragging */
  1608.     },
  1609.   { &coloritems[3], /* next item */
  1610.     10, 20, 80 , 10, /* x,y,w,h */
  1611.     COLMEMFLAGS,
  1612.     ColorExclude(2), /* mutual exclude bits */
  1613.     (APTR) &colortext[2],
  1614.     NULL, /* highlight image */
  1615.     'h', /* command byte ? */
  1616.     NULL, /* submenu item */
  1617.     0 /* next select for select dragging */
  1618.     },
  1619.   { &coloritems[4], /* next item */
  1620.     10, 30, 80 , 10, /* x,y,w,h */
  1621.     COLMEMFLAGS,
  1622.     ColorExclude(3), /* mutual exclude bits */
  1623.     (APTR) &colortext[3],
  1624.     NULL, /* highlight image */
  1625.     'h', /* command byte ? */
  1626.     NULL, /* submenu item */
  1627.     0 /* next select for select dragging */
  1628.     },
  1629.   { NULL, /* next item */
  1630.     10, 40, 80 , 10, /* x,y,w,h */
  1631.     COLMEMFLAGS,
  1632.     ColorExclude(4), /* mutual exclude bits */
  1633.     (APTR) &colortext[4],
  1634.     NULL, /* highlight image */
  1635.     'h', /* command byte ? */
  1636.     NULL, /* submenu item */
  1637.     0 /* next select for select dragging */
  1638.     }
  1639. };
  1640.  
  1641.  
  1642.  
  1643. void MenuSetColMap()
  1644. {
  1645.     int which;
  1646.  
  1647.     for( which = 0; which < ColNum; which++ ) {
  1648.         if( Selected(coloritems[which]))
  1649.             break;
  1650.     }
  1651.  
  1652.     SetHourGlassCol();
  1653.  
  1654.     switch( which ) {
  1655.     case 0:
  1656.         SetMono( 0xf, 0xf, 0xf );
  1657.         break;
  1658.     case 1:
  1659.         SetMono( 0xf, 0, 0 );
  1660.         break;
  1661.     case 2:
  1662.         SetMono( 0, 0xf, 0 );
  1663.         break;
  1664.     case 3:
  1665.         SetMono( 0x0, 0x0, 0xf );
  1666.         break;
  1667.     case 4:
  1668.         SetRainbow();
  1669.         break;
  1670.     default:
  1671.         break;
  1672.     }
  1673. }
  1674. \Rogue\Monster\
  1675. else
  1676.   echo "will not over write ./menu_color.c"
  1677. fi
  1678. if `test ! -s ./menu_files.c`
  1679. then
  1680. echo "writing ./menu_files.c"
  1681. cat > ./menu_files.c << '\Rogue\Monster\'
  1682. #include "gadgetdef.h"
  1683.  
  1684. static struct IntuiText filetext[] = {
  1685.     { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"save as", NULL },
  1686.     { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"save first", NULL },
  1687.     { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"save next", NULL },
  1688.     { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"open map", NULL },
  1689.     { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"close map", NULL }
  1690. };
  1691.  
  1692. static struct IntuiText greytext[] = {
  1693.    { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"Grey model",   NULL },
  1694.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Average",   NULL },
  1695.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Lumin",   NULL },
  1696.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Distance",   NULL },
  1697.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"R only",   NULL },
  1698.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"G only",   NULL },
  1699.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"B only",   NULL }
  1700. };
  1701.  
  1702. static struct IntuiText packtext[] = {
  1703.     { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"compression", NULL },
  1704.     { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"run length", NULL },
  1705.     { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"none", NULL }
  1706. };
  1707.  
  1708.  
  1709.  
  1710. #define FILEFLAGS  ( ITEMTEXT | HIGHCOMP | ITEMENABLED )
  1711.  
  1712. static struct MenuItem packitems[] = {
  1713.   { &packitems[1], /* next item */
  1714.     90, 0, 110 , 10, /* x,y,w,h */
  1715.     COLMEMFLAGS| CHECKED,
  1716.     2, /* mutual exclude bits */
  1717.     (APTR) &packtext[1],  /* grey */
  1718.     NULL, /* highlight image */
  1719.     'h', /* command byte ? */
  1720.     NULL, /* submenu item */
  1721.     0 /* next select for select dragging */
  1722.     },
  1723.   { NULL, /* next item */
  1724.     90, 10, 110 , 10, /* x,y,w,h */
  1725.     COLMEMFLAGS,
  1726.     1, /* mutual exclude bits */
  1727.     (APTR) &packtext[2],  /* grey */
  1728.     NULL, /* highlight image */
  1729.     'h', /* command byte ? */
  1730.     NULL, /* submenu item */
  1731.     0 /* next select for select dragging */
  1732.     }
  1733. };
  1734.  
  1735. #define GREYMUTUAL(pos) (077 ^ (1<<(pos)))
  1736. static struct MenuItem greyitems[] = {
  1737.   { &greyitems[1], /* next item */
  1738.     90, 0, 80 , 10, /* x,y,w,h */
  1739.     COLMEMFLAGS|CHECKED,
  1740.     GREYMUTUAL(0), /* mutual exclude bits */
  1741.     (APTR) &greytext[1],  /* average */
  1742.     NULL, /* highlight image */
  1743.     'h', /* command byte ? */
  1744.     NULL, /* submenu item */
  1745.     0 /* next select for select dragging */
  1746.     },
  1747.   { &greyitems[2], /* next item */
  1748.     90, 10, 80 , 10, /* x,y,w,h */
  1749.     COLMEMFLAGS,
  1750.     GREYMUTUAL(1), /* mutual exclude bits */
  1751.     (APTR) &greytext[2],  /* lumin */
  1752.     NULL, /* highlight image */
  1753.     'h', /* command byte ? */
  1754.     NULL, /* submenu item */
  1755.     0 /* next select for select dragging */
  1756.     },
  1757.   { &greyitems[3], /* next item */
  1758.     90, 20, 80 , 10, /* x,y,w,h */
  1759.     COLMEMFLAGS,
  1760.     GREYMUTUAL(2), /* mutual exclude bits */
  1761.     (APTR) &greytext[3],  /* dist */
  1762.     NULL, /* highlight image */
  1763.     'h', /* command byte ? */
  1764.     NULL, /* submenu item */
  1765.     0 /* next select for select dragging */
  1766.     },
  1767.   { &greyitems[4], /* next item */
  1768.     90, 30, 80 , 10, /* x,y,w,h */
  1769.     COLMEMFLAGS,
  1770.     GREYMUTUAL(3), /* mutual exclude bits */
  1771.     (APTR) &greytext[4],  /* dist */
  1772.     NULL, /* highlight image */
  1773.     'h', /* command byte ? */
  1774.     NULL, /* submenu item */
  1775.     0 /* next select for select dragging */
  1776.     },
  1777.   { &greyitems[5], /* next item */
  1778.     90, 40, 80 , 10, /* x,y,w,h */
  1779.     COLMEMFLAGS,
  1780.     GREYMUTUAL(4), /* mutual exclude bits */
  1781.     (APTR) &greytext[5],  /* dist */
  1782.     NULL, /* highlight image */
  1783.     'h', /* command byte ? */
  1784.     NULL, /* submenu item */
  1785.     0 /* next select for select dragging */
  1786.     },
  1787.   { NULL, /* next item */
  1788.     90, 50, 80 , 10, /* x,y,w,h */
  1789.     COLMEMFLAGS,
  1790.     GREYMUTUAL(5), /* mutual exclude bits */
  1791.     (APTR) &greytext[6],  /* dist */
  1792.     NULL, /* highlight image */
  1793.     'h', /* command byte ? */
  1794.     NULL, /* submenu item */
  1795.     0 /* next select for select dragging */
  1796.     }
  1797. };
  1798.  
  1799.  
  1800.  
  1801.  
  1802. static struct MenuItem fileitems[] = {
  1803.   { &fileitems[1], /* next item */
  1804.     10, 0, 90 , 10, /* x,y,w,h */
  1805.     FILEFLAGS,
  1806.     0, /* mutual exclude bits */
  1807.     (APTR) &filetext[0],  /* grey */
  1808.     NULL, /* highlight image */
  1809.     'h', /* command byte ? */
  1810.     NULL, /* submenu item */
  1811.     0 /* next select for select dragging */
  1812.     },
  1813.   { &fileitems[2], /* next item */
  1814.     10, 10, 90 , 10, /* x,y,w,h */
  1815.     FILEFLAGS,
  1816.     0, /* mutual exclude bits */
  1817.     (APTR) &filetext[1],  /* grey */
  1818.     NULL, /* highlight image */
  1819.     'h', /* command byte ? */
  1820.     NULL, /* submenu item */
  1821.     0 /* next select for select dragging */
  1822.     },
  1823.   { &fileitems[3], /* next item */
  1824.     10, 20, 90 , 10, /* x,y,w,h */
  1825.     FILEFLAGS,
  1826.     0, /* mutual exclude bits */
  1827.     (APTR) &filetext[2],  /* grey */
  1828.     NULL, /* highlight image */
  1829.     'h', /* command byte ? */
  1830.     NULL, /* submenu item */
  1831.     0 /* next select for select dragging */
  1832.     },
  1833.   { &fileitems[4], /* next item */
  1834.     10, 30, 90 , 10, /* x,y,w,h */
  1835.     FILEFLAGS,
  1836.     0, /* mutual exclude bits */
  1837.     (APTR) &packtext[0],  /* grey */
  1838.     NULL, /* highlight image */
  1839.     'h', /* command byte ? */
  1840.     packitems, /* submenu item */
  1841.     0 /* next select for select dragging */
  1842.     },
  1843.   { &fileitems[5], /* next item */
  1844.     10, 40, 90 , 10, /* x,y,w,h */
  1845.     FILEFLAGS,
  1846.     0, /* mutual exclude bits */
  1847.     (APTR) &filetext[3],  /* grey */
  1848.     NULL, /* highlight image */
  1849.     'h', /* command byte ? */
  1850.     NULL, /* submenu item */
  1851.     0 /* next select for select dragging */
  1852.     },
  1853.   { &fileitems[6], /* next item */
  1854.     10, 50, IMAGE_HITWIDTH , 10, /* x,y,w,h */
  1855.     COLMEMFLAGS,
  1856.     1, /* mutual exclude bits */
  1857.     (APTR) &greytext[0],     /* red */
  1858.     NULL, /* highlight image */
  1859.     'h', /* command byte ? */
  1860.     greyitems, /* submenu item */
  1861.     0 /* next select for select dragging */
  1862.     },
  1863.   { NULL, /* next item */
  1864.     10, 60, 90 , 10, /* x,y,w,h */
  1865.     FILEFLAGS,
  1866.     0, /* mutual exclude bits */
  1867.     (APTR) &filetext[4],  /* grey */
  1868.     NULL, /* highlight image */
  1869.     'h', /* command byte ? */
  1870.     NULL, /* submenu item */
  1871.     0 /* next select for select dragging */
  1872.     }
  1873. };
  1874.  
  1875. extern char *GetOutFile();
  1876. extern char *GetInFile();
  1877.  
  1878. MenuDoFile(item)
  1879. int item;
  1880. {
  1881.     static int filecnt = 0;
  1882.     char tempbuff[80];
  1883.     char *filename;
  1884.     bool packflag;
  1885.     int i;
  1886.  
  1887.     packflag = Selected( packitems[0] )?1:0;
  1888.  
  1889.  
  1890.     switch (item ) {
  1891.     case 0:
  1892.         if( (filename = GetOutFile())) {
  1893.             SetHourGlass();
  1894.             WriteIlbm(filename, &SurfWinDef, &SurfScrnDef, packflag);
  1895.         }
  1896.         break;
  1897.     case 1:
  1898.         filecnt = 0; /* deliberate fall into case 2 */
  1899.     case 2:
  1900.         if( filename = GetOutFile()) {
  1901.             SetHourGlass();
  1902.             sprintf(tempbuff, "%s.%d", filename, filecnt++ );
  1903.             WriteIlbm(tempbuff, &SurfWinDef, &SurfScrnDef, packflag);
  1904.         }
  1905.         break;
  1906.     case 4:
  1907.         if( filename = GetInFile()){
  1908.             SetHourGlass();
  1909.             ReadIlbm( filename);
  1910.         }
  1911.         break;
  1912.     case 5:
  1913.         for( i = 0; i < (sizeof(greyitems)/sizeof(greyitems[0])); i++ ) {
  1914.             if( Selected(greyitems[i])) {
  1915.                 SetGreyModel(i);
  1916.             }
  1917.         }
  1918.         break;
  1919.     case 6:
  1920.         CloseImgPix();
  1921.         break;
  1922.     default:
  1923.         break;
  1924.     }
  1925.  
  1926.     ClearHourGlass();
  1927. }
  1928. \Rogue\Monster\
  1929. else
  1930.   echo "will not over write ./menu_files.c"
  1931. fi
  1932. if `test ! -s ./menu_image.c`
  1933. then
  1934. echo "writing ./menu_image.c"
  1935. cat > ./menu_image.c << '\Rogue\Monster\'
  1936. #include "menuexp.h"
  1937.  
  1938. /*
  1939.  * Menu description for selecting color mapping
  1940.  */
  1941. static struct IntuiText Specular = {
  1942.      0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Specular",  NULL
  1943. };
  1944.  
  1945. static struct IntuiText revtext[] = {
  1946.    { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"Rev. Axis",  NULL },
  1947.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"X",   NULL },
  1948.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Y",   NULL }
  1949. };
  1950.  
  1951. static struct IntuiText dithertext[] = {
  1952.    { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"Dither",   NULL },
  1953.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"none",   NULL },
  1954.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"half",   NULL },
  1955.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"full",   NULL }
  1956. };
  1957.  
  1958.  
  1959. static struct IntuiText MiscText[] = {
  1960.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Abort Draw",   NULL },
  1961.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Debug",   NULL },
  1962.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Flip XY Map", NULL }
  1963. };
  1964.  
  1965. struct MenuItem revitems[] = {
  1966.   { &revitems[1], /* next item */
  1967.     90, 0, 80 , 10, /* x,y,w,h */
  1968.     COLMEMFLAGS| CHECKED,
  1969.     2, /* mutual exclude bits */
  1970.     (APTR) &revtext[1],  /* grey */
  1971.     NULL, /* highlight image */
  1972.     'h', /* command byte ? */
  1973.     NULL, /* submenu item */
  1974.     0 /* next select for select dragging */
  1975.     },
  1976.   { NULL, /* next item */
  1977.     90, 10, 80 , 10, /* x,y,w,h */
  1978.     COLMEMFLAGS,
  1979.     1, /* mutual exclude bits */
  1980.     (APTR) &revtext[2],  /* grey */
  1981.     NULL, /* highlight image */
  1982.     'h', /* command byte ? */
  1983.     NULL, /* submenu item */
  1984.     0 /* next select for select dragging */
  1985.     }
  1986. };
  1987.  
  1988. struct MenuItem ditheritems[] = {
  1989.   { &ditheritems[1], /* next item */
  1990.     90, 0, 80 , 10, /* x,y,w,h */
  1991.     COLMEMFLAGS,
  1992.     2|4, /* mutual exclude bits */
  1993.     (APTR) &dithertext[1],  /* grey */
  1994.     NULL, /* highlight image */
  1995.     'h', /* command byte ? */
  1996.     NULL, /* submenu item */
  1997.     0 /* next select for select dragging */
  1998.     },
  1999.   { &ditheritems[2], /* next item */
  2000.     90, 10, 80 , 10, /* x,y,w,h */
  2001.     COLMEMFLAGS,
  2002.     4|1, /* mutual exclude bits */
  2003.     (APTR) &dithertext[2],  /* grey */
  2004.     NULL, /* highlight image */
  2005.     'h', /* command byte ? */
  2006.     NULL, /* submenu item */
  2007.     0 /* next select for select dragging */
  2008.     },
  2009.   { NULL, /* next item */
  2010.     90, 20, 80 , 10, /* x,y,w,h */
  2011.     COLMEMFLAGS| CHECKED,
  2012.     1|2, /* mutual exclude bits */
  2013.     (APTR) &dithertext[3],  /* grey */
  2014.     NULL, /* highlight image */
  2015.     'h', /* command byte ? */
  2016.     NULL, /* submenu item */
  2017.     0 /* next select for select dragging */
  2018.     }
  2019. };
  2020.  
  2021.  
  2022. #define IMAGE_HITWIDTH 96
  2023.  
  2024. struct MenuItem imageitems[] = {
  2025.   { &imageitems[1], /* next item */
  2026.     1, 0, IMAGE_HITWIDTH , 10, /* x,y,w,h */
  2027.     COLMEMFLAGS,
  2028.     2, /* mutual exclude bits */
  2029.     (APTR) &revtext[0],  /* grey */
  2030.     NULL, /* highlight image */
  2031.     'h', /* command byte ? */
  2032.     revitems, /* submenu item */
  2033.     0 /* next select for select dragging */
  2034.     },
  2035.   { &imageitems[2], /* next item */
  2036.     1, 10, IMAGE_HITWIDTH , 10, /* x,y,w,h */
  2037.     COLMEMFLAGS,
  2038.     1, /* mutual exclude bits */
  2039.     (APTR) &dithertext[0],     /* red */
  2040.     NULL, /* highlight image */
  2041.     'h', /* command byte ? */
  2042.     ditheritems, /* submenu item */
  2043.     0 /* next select for select dragging */
  2044.     },
  2045.   { &imageitems[3], /* next item */
  2046.     1, 20, IMAGE_HITWIDTH , 10, /* x,y,w,h */
  2047.     COLMEMFLAGS|MENUTOGGLE,
  2048.     0, /* mutual exclude bits */
  2049.     (APTR) &Specular,
  2050.     NULL, /* highlight image */
  2051.     'h', /* command byte ? */
  2052.     NULL, /* submenu item */
  2053.     0 /* next select for select dragging */
  2054.     },
  2055.   { &imageitems[4], /* next item */
  2056.     1, 30, IMAGE_HITWIDTH , 10, /* x,y,w,h */
  2057.     COLMEMFLAGS|MENUTOGGLE,
  2058.     0, /* mutual exclude bits */
  2059.     (APTR) &MiscText[2], /* Flip XY */
  2060.     NULL, /* highlight image */
  2061.     'h', /* command byte ? */
  2062.     NULL, /* submenu item */
  2063.     0 /* next select for select dragging */
  2064.     },
  2065.   { &imageitems[5], /* next item */
  2066.     1, 40, 100 , 10, /* x,y,w,h */
  2067.     COLMEMFLAGS| MENUTOGGLE,
  2068.     0, /* mutual exclude bits */
  2069.     (APTR) &MiscText[0], /* AbortDraw */
  2070.     NULL, /* highlight image */
  2071.     'h', /* command byte ? */
  2072.     NULL, /* submenu item */
  2073.     0 /* next select for select dragging */
  2074.     },
  2075.   { NULL, /* next item */
  2076.     1, 50, IMAGE_HITWIDTH, 10, /* x,y,w,h */
  2077.     COLMEMFLAGS|MENUTOGGLE,
  2078.     0, /* mutual exclude bits */
  2079.     (APTR) &MiscText[1],   /* debug */
  2080.     NULL, /* highlight image */
  2081.     'h', /* command byte ? */
  2082.     NULL, /* submenu item */
  2083.     0 /* next select for select dragging */
  2084.     }
  2085. };
  2086.  
  2087. USHORT *AbortDrawPtr = &imageitems[4].Flags;
  2088. USHORT *DebugOnPtr = &imageitems[5].Flags;
  2089.  
  2090.  
  2091. static void MenuSetImage()
  2092. {
  2093.     if( Selected(revitems[0])) {
  2094.         SetRevAxis(0); /* Xaxis */
  2095.     }
  2096.     else {
  2097.         SetRevAxis(1); /* Yaxis */
  2098.     }
  2099.  
  2100.     if( Selected(ditheritems[0])) {
  2101.         DitherMask = 0;
  2102.     }
  2103.     else if (Selected(ditheritems[1] ) ) {
  2104.         DitherMask = 4;
  2105.     }
  2106.     else {
  2107.         DitherMask = 7;
  2108.     }
  2109.     SpecOn = Selected( imageitems[2])?true:false;
  2110.     FlipImgPix( Selected(imageitems[3])?true:false);
  2111. }
  2112.  
  2113. \Rogue\Monster\
  2114. else
  2115.   echo "will not over write ./menu_image.c"
  2116. fi
  2117. if `test ! -s ./menu_scrn.c`
  2118. then
  2119. echo "writing ./menu_scrn.c"
  2120. cat > ./menu_scrn.c << '\Rogue\Monster\'
  2121. #include "scrndef.h"
  2122. /*
  2123.  * Menu description for selecting color mapping
  2124.  */
  2125.  
  2126. /*
  2127.  * define mutual exclusion flags
  2128.  */
  2129. #define MUBIT1 1
  2130. #define MUBIT2 2
  2131. #define MUBIT3 4
  2132. #define MUBIT4 8
  2133. #define MUBIT5 16
  2134. #define MULO 32
  2135. #define MUHI 64
  2136. #define MUHAM 128
  2137. #define MUOVER 256
  2138.  
  2139. static struct IntuiText scrntext[] = {
  2140.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"2 color",  NULL },
  2141.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"4 color ",   NULL },
  2142.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"8 color", NULL },
  2143.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"16 color",  NULL },
  2144.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"32 color",  NULL },
  2145.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"lores",  NULL },
  2146.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"hires",  NULL },
  2147.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"ham",  NULL },
  2148.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"overscan",  NULL },
  2149.    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"interlace",  NULL },
  2150. };
  2151.  
  2152. static struct MenuItem scrnitems[] = {
  2153.   { &scrnitems[1], /* next item */
  2154.     10, 0, 90 , 10, /* x,y,w,h */
  2155.     COLMEMFLAGS ,
  2156.     MUBIT2|MUBIT3|MUBIT4|MUBIT5, /* mutual exclude bits */
  2157.     (APTR) &scrntext[0],  /* grey */
  2158.     NULL, /* highlight image */
  2159.     'h', /* command byte ? */
  2160.     NULL, /* submenu item */
  2161.     0 /* next select for select dragging */
  2162.     },
  2163.   { &scrnitems[2], /* next item */
  2164.     10, 10, 90 , 10, /* x,y,w,h */
  2165.     COLMEMFLAGS,
  2166.     MUBIT1|MUBIT3|MUBIT4|MUBIT5, /* mutual exclude bits */
  2167.     (APTR) &scrntext[1],  /* grey */
  2168.     NULL, /* highlight image */
  2169.     'h', /* command byte ? */
  2170.     NULL, /* submenu item */
  2171.     0 /* next select for select dragging */
  2172.     },
  2173.   { &scrnitems[3], /* next item */
  2174.     10, 20, 90 , 10, /* x,y,w,h */
  2175.     COLMEMFLAGS,
  2176.     MUBIT1|MUBIT2|MUBIT4|MUBIT5, /* mutual exclude bits */
  2177.     (APTR) &scrntext[2],  /* grey */
  2178.     NULL, /* highlight image */
  2179.     'h', /* command byte ? */
  2180.     NULL, /* submenu item */
  2181.     0 /* next select for select dragging */
  2182.     },
  2183.   { &scrnitems[4], /* next item */
  2184.     10, 30, 90 , 10, /* x,y,w,h */
  2185.     COLMEMFLAGS| CHECKED,
  2186.     MUBIT1|MUBIT2|MUBIT3|MUBIT5, /* mutual exclude bits */
  2187.     (APTR) &scrntext[3],  /* grey */
  2188.     NULL, /* highlight image */
  2189.     'h', /* command byte ? */
  2190.     NULL, /* submenu item */
  2191.     0 /* next select for select dragging */
  2192.     },
  2193.   { &scrnitems[5], /* next item */
  2194.     10, 40, 90 , 10, /* x,y,w,h */
  2195.     COLMEMFLAGS,
  2196.     MUBIT1|MUBIT2|MUBIT3|MUBIT4|MUHI, /* mutual exclude bits */
  2197.     (APTR) &scrntext[4],  /* grey */
  2198.     NULL, /* highlight image */
  2199.     'h', /* command byte ? */
  2200.     NULL, /* submenu item */
  2201.     0 /* next select for select dragging */
  2202.     },
  2203.   { &scrnitems[6], /* next item */
  2204.     10, 50, 90 , 10, /* x,y,w,h */
  2205.     COLMEMFLAGS| CHECKED,
  2206.     MUHI|MUHAM, /* mutual exclude bits */
  2207.     (APTR) &scrntext[5],  /* grey */
  2208.     NULL, /* highlight image */
  2209.     'h', /* command byte ? */
  2210.     NULL, /* submenu item */
  2211.     0 /* next select for select dragging */
  2212.     },
  2213.   { &scrnitems[7], /* next item */
  2214.     10, 60, 90 , 10, /* x,y,w,h */
  2215.     COLMEMFLAGS,
  2216.     MULO|MUHAM|MUBIT5, /* mutual exclude bits */
  2217.     (APTR) &scrntext[6],  /* grey */
  2218.     NULL, /* highlight image */
  2219.     'h', /* command byte ? */
  2220.     NULL, /* submenu item */
  2221.     0 /* next select for select dragging */
  2222.     },
  2223.   { &scrnitems[8], /* next item */
  2224.     10, 70, 90 , 10, /* x,y,w,h */
  2225.     (COLMEMFLAGS) & ~ITEMENABLED,
  2226.     MULO|MUHI, /* mutual exclude bits */
  2227.     (APTR) &scrntext[7],  /* grey */
  2228.     NULL, /* highlight image */
  2229.     'h', /* command byte ? */
  2230.     NULL, /* submenu item */
  2231.     0 /* next select for select dragging */
  2232.     },
  2233.   { &scrnitems[9], /* next item */
  2234.     10, 80, 90 , 10, /* x,y,w,h */
  2235.     ( COLMEMFLAGS|MENUTOGGLE)& ~ITEMENABLED ,
  2236.     0, /* mutual exclude bits */
  2237.     (APTR) &scrntext[8],  /* grey */
  2238.     NULL, /* highlight image */
  2239.     'h', /* command byte ? */
  2240.     NULL, /* submenu item */
  2241.     0 /* next select for select dragging */
  2242.     },
  2243.   { NULL, /* next item */
  2244.     10, 90, 90 , 10, /* x,y,w,h */
  2245.     COLMEMFLAGS|MENUTOGGLE,
  2246.     0, /* mutual exclude bits */
  2247.     (APTR) &scrntext[9],  /* grey */
  2248.     NULL, /* highlight image */
  2249.     'h', /* command byte ? */
  2250.     NULL, /* submenu item */
  2251.     0 /* next select for select dragging */
  2252.     }
  2253. };
  2254.  
  2255.  
  2256.  
  2257. void MenuSetScrn()
  2258. {
  2259.     UBYTE colmax;
  2260.  
  2261.     CloseSurf();
  2262.  
  2263.     /*
  2264.      * overscan
  2265.      */
  2266.     SurfScrnDef.Width = 320;
  2267.     SurfScrnDef.Height = 200+ButHeight;
  2268.     SurfScrnDef.LeftEdge = SurfScrnDef.TopEdge = 0;
  2269.  
  2270.     if( Selected(scrnitems[8])) {
  2271.         SurfScrnDef.Width = 352;
  2272.         SurfScrnDef.Height = 220;
  2273.     }
  2274.  
  2275.     if( Selected(scrnitems[7])) { /* ham mode */
  2276.         SurfScrnDef.Depth = 6;
  2277.         SurfScrnDef.ViewModes = HAM;
  2278.     }
  2279.     else {
  2280.         int i;
  2281.         SurfScrnDef.Depth = 3; /* incase non of the flags are set */
  2282.  
  2283.         for( i = 0; i < 5; i++ ) {
  2284.             if( Selected( scrnitems[i])) {
  2285.                 SurfScrnDef.Depth = i+1;
  2286.             }
  2287.         }
  2288.  
  2289.         if( Selected( scrnitems[5] ) ) { /* lores */
  2290.             SurfScrnDef.ViewModes = 0;
  2291.         }
  2292.         else {
  2293.             SurfScrnDef.ViewModes = HIRES;
  2294.             SurfScrnDef.Width <<= 1;
  2295.             SurfScrnDef.LeftEdge *= 2;
  2296.             if( SurfScrnDef.Depth > 4 ) {
  2297.                 SurfScrnDef.Depth = 4;
  2298.             }
  2299.         }
  2300.     }
  2301.  
  2302.     if( Selected( scrnitems[9] )) {   /* interlace */
  2303.         SurfScrnDef.Height <<= 1;
  2304.         SurfScrnDef.Height -= ButHeight;
  2305.         SurfScrnDef.TopEdge *= 2;
  2306.         SurfScrnDef.ViewModes |= LACE;
  2307.     }
  2308.  
  2309.  
  2310.     OpenSurf();
  2311. }
  2312. \Rogue\Monster\
  2313. else
  2314.   echo "will not over write ./menu_scrn.c"
  2315. fi
  2316. echo "Finished archive 2 of 3"
  2317. # if you want to concatenate archives, remove anything after this line
  2318. exit
  2319. -- 
  2320. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  2321. "I can't tell the difference between ABC News and Hill Street Blues" -Bono
  2322.